/**
 *
 *
 * @param {*} number  第几位
 * @param {*} src 名片头像
 * @param {*} name 名片名字
 * @param {*} qrCodeUrl 小程序codeURL图片
 */
const wxml0 = (name, pic)=>{
	return `
		<view class="topBgBox">
			<image src="${pic}" class="topBgImg"/>
			<text class="topBgTxt">${name}</text>
			
		</view>
		`
}
const wxml1 = (name, pic)=>{
	return `
		<view class="bottom">
			<image src="${pic}" class="qr"/>
			<text class="msg">扫码查看详情</text>
		</view>
		`
}

const wxml = (type, item) => {
	// 产品详情
	let topMsg, pageMsg1, pageMsg2, pageMsg3, pageMsg4, pageMsg5,pageMsg7,pageMsg8 = ''

	if (type == 1) { // 产品详情的
		// for (let item of listMsg) {
			if(item.name == '介绍'){
				topMsg = item
			}
			else if (item.name == '适用对象') {
				pageMsg1 = item
			} else if (item.name == '产品优势') {
				pageMsg2 = item
			} else if (item.name == '服务案例') {
				pageMsg3 = item
			} else if (item.name == '办理流程') {
				pageMsg4 = item
			} else if (item.name == '办理材料') {
				pageMsg5 = item
			} else if ( item.name == '功能介绍' ) {
				pageMsg8 = item
			} 
		// }
	}else{ // 方案详情
		// for (let item of listMsg) {
			if(item.name == '介绍'){
				topMsg = item
			}
			else if (item.name == '客户痛点') {
				pageMsg1 = item
			} else if (item.name == '解决方案') {
				pageMsg3 = item
			} else if (item.name == '方案优势') {
				pageMsg5 = item
			} else if (item.name == '适用场景') {
				pageMsg7 = item
			} 
		// }
	}
	let func0 = (msg) => {
		let itemMsg = ''
		for (let [idx, it] of msg.entries()) {
			itemMsg += `<view>
					<text class="topBoxTxt${idx+1}">${it.content[0]}</text>
				</view>`
		}
		return itemMsg
	}
	let topMsgText =''
	if(topMsg){
		topMsgText = `
			<view class="topBox radiusBox">
				<image class="titlebgImg" src="${topMsg.topBgImg}"></image>
				
				<view class="topBoxTxt">
					${func0(topMsg.val)}
				</view>
			</view>
		`
	}

	let func1 = (msg) => {
		let itemMsg = ''
		for (let [idx, it] of msg.entries()) {
			itemMsg += `<view class="topOneItem">
					<text class="contentTxt${idx+1}">${it.content[0]}</text>
				</view>`
		}
		return itemMsg
	}
	let pageMsg1Text = ''
	if (pageMsg1) {
		pageMsg1Text = `
			<view class="radiusBox mgTopBox">
				<view class="titleBox">
					<image class="bottomImg" src="${pageMsg1.titleBgImg}"></image>
					<view class="topTxt">
						<image class="topTxtImg" src="${pageMsg1.iconImg}"></image>
						<text class="titleTxt">${pageMsg1.name}</text>
					</view>
				</view>
				<view class="longHeightTxtBox1">
					${func1(pageMsg1.val)}
				</view>
			</view>
			`
	}
	let func2 = (msg) => {
		let itemMsg = ''
		for (let [idx, it] of msg.entries()) {
			itemMsg += `<view class="topTwoItem">
					<text class="content2Txt${idx+1}">${it.title||''}${it.content[0]}</text>
				</view>`
		}
		return itemMsg
	}

	let pageMsg2Text = ''
	if (pageMsg2) {
		pageMsg2Text = `
			<view class="radiusBox mgTopBox">
				<view class="titleBox">
					<image class="bottomImg" src="${pageMsg2.titleBgImg}"></image>
					<view class="topTxt">
						<image class="topTxtImg" src="${pageMsg2.iconImg}"></image>
						<text class="titleTxt">${pageMsg2.name}</text>
					</view>
				</view>
				<view class="longHeightTxtBox2">
					${func2(pageMsg2.val)}
				</view>
			</view>
			`
	}


	let func3 = (msg) => {
		let func3Small = (msgArr, idx) => {
			let smallMsg = ''
			for (let [n, i] of msgArr.entries()) {
				smallMsg += `<text class="pageText3Box${idx+1}Txt${n+1}">${i.name}</text>`
			}
			return smallMsg
		}
		let itemMsg = ''
		for (let [idx, it] of msg.entries()) {
			if(it.title){
				itemMsg += `
					<view class="pageText3Box ">
						<text class="pageText3BoxTitle">${it.title}</text>
						<view>
							${func3Small(it.heights,idx)}
						</view>
					</view>
				`
			}else{
				itemMsg += `
					<view class="pageText3Box ">
						<view>
							${func3Small(it.heights,idx)}
						</view>
					</view>
				`
			}
			
		}
		return itemMsg
	}

	let pageMsg3Text = ''
	if (pageMsg3) {
		pageMsg3Text = `
			<view class="radiusBox mgTopBox">
				<view class="titleBox">
					<image class="bottomImg" src="${pageMsg3.titleBgImg}"></image>
					<view class="topTxt">
						<image class="topTxtImg" src="${pageMsg3.iconImg}"></image>
						<text class="titleTxt">${pageMsg3.name}</text>
					</view>
				</view>
				<view class="longHeightTxtBox3">
					${func3(pageMsg3.val)}
				</view>
			</view>
			`
	}
	
	
	let func4 = (msg) => {
		let itemMsg = ''
		for (let [idx, it] of msg.entries()) {
			itemMsg += `<view class="topOneItem">
					<text class="banliTxt${idx+1}">${it.content[0]}</text>
				</view>`
		}
		return itemMsg
	}
	let pageMsg4Text = ''
	if (pageMsg4) {
		pageMsg4Text = `
			<view class="radiusBox mgTopBox">
				<view class="titleBox">
					<image class="bottomImg" src="${pageMsg4.titleBgImg}"></image>
					<view class="topTxt">
						<image class="topTxtImg" src="${pageMsg4.iconImg}"></image>
						<text class="titleTxt">${pageMsg4.name}</text>
					</view>
				</view>
				<view class="longHeightTxtBox4">
					${func4(pageMsg4.val)}
				</view>
			</view>
			`
	}
	
	let func5 = (msg) => {
		let itemMsg = ''
		for (let [idx, it] of msg.entries()) {
			itemMsg += `<view>
					<text class="cailiaoTxt${idx+1}">${it.content[0]}</text>
				</view>`
		}
		return itemMsg
	}
	let pageMsg5Text = ''
	if (pageMsg5) {
		pageMsg5Text = `
			<view class="radiusBox mgTopBox">
				<view class="titleBox">
					<image class="bottomImg" src="${pageMsg5.titleBgImg}"></image>
					<view class="topTxt">
						<image class="topTxtImg" src="${pageMsg5.iconImg}"></image>
						<text class="titleTxt">${pageMsg5.name}</text>
					</view>
				</view>
				<view class="longHeightTxtBox5">
					${func5(pageMsg5.val)}
				</view>
			</view>
			`
	}
	
	let func7 = (msg) => {
		let itemMsg = ''
		for (let [idx, it] of msg.entries()) {
			itemMsg += `<view>
					<text class="changjing${idx+1}">${it.content[0]}</text>
				</view>`
		}
		return itemMsg
	}
	let pageMsg7Text = ''
	if (pageMsg7) {
		pageMsg7Text = `
			<view class="radiusBox mgTopBox">
				<view class="titleBox">
					<image class="bottomImg" src="${pageMsg7.titleBgImg}"></image>
					<view class="topTxt">
						<image class="topTxtImg" src="${pageMsg7.iconImg}"></image>
						<text class="titleTxt">${pageMsg7.name}</text>
					</view>
				</view>
				<view class="longHeightTxtBox7">
					${func7(pageMsg7.val)}
				</view>
			</view>
			`
	}
	
	let func8 = (msg) => {
		let itemMsg = ''
		for (let [idx, it] of msg.entries()) {
			itemMsg += `<view class="topTwoItem">
					<text class="content2Txt${idx+1}">${it.title||''}${it.content[0]}</text>
				</view>`
		}
		return itemMsg
	}
	let pageMsg8Text = ''
	if (pageMsg8) {
		pageMsg8Text = `
		<view class="radiusBox mgTopBox">
			<view class="titleBox">
				<image class="bottomImg" src="${pageMsg8.titleBgImg}"></image>
				<view class="topTxt">
					<image class="topTxtImg" src="${pageMsg8.iconImg}"></image>
					<text class="titleTxt">${pageMsg8.name}</text>
				</view>
			</view>
			<view class="longHeightTxtBox2">
				${func8(pageMsg8.val)}
			</view>
		</view>
		`
	}
	// <image src="${pic}"  class="pic"/>
	// <text class="name color size">${name}</text>
	return `
		<view class="container">
			
			${topMsgText}
			${pageMsg7Text}
			${pageMsg1Text}
			${pageMsg2Text}
			${pageMsg3Text}
			${pageMsg4Text}
			${pageMsg5Text}
			${pageMsg8Text}
		</view>
		`
}

// <view class="bottom">
// 				<image src="${pic}"  class="qr"/>
// 				<text class="msg">扫码一起加入吧</text>
// 			</view>
/**
 *
 *
 * @param {*} screenWidth 屏幕宽度
 * @param {*} canvasWidth  画布宽度
 * @param {*} canvasHeight  画布高度
 * @param {*} numberWidth  数字宽度，动态设置
 * @return {*} 
 */
const style = (screenScale,screenWidth, canvasWidth, canvasHeight, item) => {

	const styleObj = {}
	// for (let [index, item] of pageMsg.entries()) {
		if(item.name == '介绍'){			// 简介
			styleObj['topBox'] = {
				height: (item.height + 20) * screenScale,
				width: canvasWidth * 0.94,
				borderRadius: 15,
			}
			styleObj['topBoxTxt'] = {
				height: (item.height + 20) * screenScale,
				marginTop: 20,
			}
			for (let [idx, it] of item.val.entries()) {
				styleObj['topBoxTxt' + (idx + 1)] = {
					height: (it.height) * screenScale,
					fontSize:13 * screenScale
				}
			}
		}else if (item.name == '适用对象' || item.name == '客户痛点' ) {
			styleObj['longHeightTxtBox1'] = {
				height: (item.height + 20) * screenScale,
			}
			for (let [idx, it] of item.val.entries()) {
				styleObj['contentTxt' + (idx + 1)] = {
					height: (it.height) * screenScale,
					fontSize:13 * screenScale
				}
			}
		} else if (item.name == '产品优势' || item.name == '功能介绍') {
			styleObj['longHeightTxtBox2'] = {
				height: (item.height + 20) * screenScale,
				
			}
			for (let [idx, it] of item.val.entries()) {
				styleObj['content2Txt' + (idx + 1)] = {
					height: (it.height) * screenScale,
					fontSize:13 * screenScale
				}
			}
		} else if (item.name == '服务案例' || item.name == '解决方案') {
			let addHeight = (item.height +40) * screenScale
			for (let [idx, it] of item.val.entries()) {
				addHeight += 25 * screenScale
				for (let [n, i] of it.heights.entries()) {
					styleObj['pageText3Box' + (idx + 1) + 'Txt' + (n + 1)] = {
						height: (i.height) * screenScale,
						fontSize:13 * screenScale
					}
				}
			}
			styleObj['longHeightTxtBox3'] = {
					height: addHeight ,
				}
		}else if(item.name == '办理流程'){
			styleObj['longHeightTxtBox4'] = {
				height: (item.height + 10) * screenScale,
			}
			for (let [idx, it] of item.val.entries()) {
				styleObj['banliTxt' + (idx + 1)] = {
					height: it.height * screenScale,
					fontSize:13 * screenScale
				}
			}
		}else if(item.name == '办理材料'|| item.name == '方案优势'){
			styleObj['longHeightTxtBox5'] = {
				height: item.height * screenScale ,
			}
			for (let [idx, it] of item.val.entries()) {
				styleObj['cailiaoTxt' + (idx + 1)] = {
					height: it.height * screenScale,
					fontSize:13 * screenScale
				}
			}
		}else if( item.name == '适用场景'){
			styleObj['longHeightTxtBox7'] = {
				height: (item.height + 4) * screenScale,
			}
			for (let [idx, it] of item.val.entries()) {
				styleObj['changjing' + (idx + 1)] = {
					height: it.height * screenScale,
					fontSize:13 * screenScale
				}
			}
		}
	// }

	// console.log(styleObj)
	return {
		...styleObj,
		"container": {
			width: canvasWidth,
			height: canvasHeight,
			position: 'relative',
			overflow: 'hidden',
			backgroundColor: '#ffffff',
			color: '#3B384B',
			marginBottom:15,
			paddingBottom:10,
		},
		"topBgBox":{
			width: canvasWidth,
			height:230,
			position:'absolute',
			left:0,
			top:0,
			
		},
		"topBgImg":{
			width: canvasWidth,
			height:230,
		},
		"blockHeight":{
			height:6,
			width:canvasWidth*0.7,
			marginLeft:canvasWidth*0.15,
			backgroundColor:'#eee'
		},
		"topBgTxt": {
			fontSize: 24,
			fontWeight:800,
			color: '#006548',
			position:'absolute',
			top:58,
			left: 14,
			width: canvasWidth * 0.55,
			height: 95,
			textAlign: 'center',
			verticalAlign:'middle'
		},
		"pic": {
			width: canvasWidth * 0.3,
			height: canvasWidth * 0.3,
			marginTop: canvasWidth * 0.1,
			marginLeft: canvasWidth * 0.35,
			marginBottom: canvasWidth * 0.05,
			borderRadius: screenWidth * 0.14,
			overflow: 'hidden',
		},
		"bottom": {
			width: canvasWidth,
			height: screenWidth * 0.2,
			flexDirection: 'row',
			justifyContent: 'self-start',
			alignItems: 'center',
			backgroundColor: '#fff',
			position: 'absolute',
			bottom: 0,
			left: 0,
		},
		"qr": {
			width: canvasWidth * 0.14,
			height: canvasWidth * 0.14,
			marginLeft: canvasWidth * 0.04,
			marginRight: canvasWidth * 0.04,
		},
		"msg": {
			fontSize: 14,
			color: '#a1a1a1',
			width: canvasWidth * 0.74,
			height: 14,
			textAlign: 'left'
		},



		"radiusBox": {
			padding: 10,
			backgroundColor: '#f8f8f8',
			// borderRadius: 30,
			overflow:'hidden',
			marginBottom: 15,
			marginLeft: canvasWidth * 0.03,
			width: canvasWidth * 0.94,
			position: 'relative',
			fontSize: 13 * screenScale,
			// height: 200
		},
		
		"mgTopBox":{
			marginTop:8,
		},
		"changjingBg":{
			height:59,
			width:canvasWidth*0.5,
			position:'absolute',
			top: -30,
			left: canvasWidth * 0.22,
		},
		'changjingBgImg':{
			height:59,
			width:canvasWidth*0.5,
		},
		// 产品介绍
		"titlebgImg": {
			position: 'absolute',
			top: 0,
			left: 0,
			height: 25,
			width: 103,
		},
		


		// 适用对象
		// "longHeightTxtBox1": {
		// 	height: pageMsg[1].height + 10,
		// },
		// // 产品优势
		// "longHeightTxtBox2": {
		// 	height: pageMsg[2].height + 25,
		// },

		// 服务案例
		// "longHeightTxtBox3": {
		// 	height: pageMsg[3].height + 50,
		// },
		"pageText3BoxTitle": {
			height: 26,
			
			// lineHeight: 28,
			fontSize: 15,
			color: '#3B384B',
			// paddingTop: 5,
		},

		"topOneItem": {
			// paddingTop: 2,
			// paddingBottom: 2,
			marginBottom: 2,
		},
		"topTwoItem": {
			// paddingTop: 3,
			// paddingBottom: 4,
			marginBottom: 2,
			// flexDirection: 'row',
			// alignSelf: 'flex-start',

		},
		// "pageMsg2LeftTitle": {
		// 	width: 66,
		// },
		// "contentTxt": {
		// 	width: canvasWidth * 0.7,
		// },



		"titleBox": {
			width: canvasWidth * 0.8,
			// height: 25,
			position: 'relative',
			marginBottom: 15
		},
		"topTxt": {
			color: '#3B384B',
			fontSize: 15,
			// fontWeight: 700,
			paddingLeft: 5,
			// height: 25,
			width: canvasWidth * 0.9,
			flexDirection: 'row',
		},
		"topTxtImg": {
			height: 30,
			width: 30,
			// verticalAlign: 'text-bottom',
			marginRight: 5,
			marginTop: -7,
		},
		"bottomImg": {
			height: 10,
			width: 164,
			position: 'absolute',
			left: -2,
			top: 20,
		},
		"titleTxt": {
			height: 25,
			width: canvasWidth * 0.9,
			fontSize: 16,
			textAlign: 'left',
			verticalAlign: 'middle',
			color: '#3B384B',
			whiteSpace: 'pre-wrap'
		},

	}

}


module.exports = {
	wxml0,
	wxml1,
	wxml,
	style
}
